#!/usr/bin/env coffee

> ./STRIPE.coffee

n = 0
customer = 'cus_PNShbMnVo5L9gd'
opt = {
  limit: 2
  customer
}


await do =>
  loop
    {
      has_more
      data:li
    } = await STRIPE.setupIntents.list(opt)

    console.log has_more
    for i from li
      console.log JSON.stringify(i)
      # console.log i.status, i.customer, new Date(i.created * 1000).toISOString()
      # if i.status == 'succeeded'
      #   paym = await STRIPE.paymentMethods.retrieve(i.payment_method)
      #   pay = await STRIPE.paymentIntents.create({
      #     amount: 12345 # 123.45欧元
      #     currency: 'eur'
      #     setup_future_usage: 'off_session'
      #     customer: i.customer # 用户的customer id
      #     payment_method: i.payment_method # 用户的payment method id
      #     confirm: true
      #     automatic_payment_methods:
      #       enabled: true
      #       allow_redirects: 'never'
      #     # error_on_requires_action: true
      #   })
      #   console.log pay.status, pay.amount_received, pay.id
      # return

    if not has_more
      break

    opt.starting_after = li.pop().id
    return


process.exit()

